
import axios from "axios";
import store from "@/store";
import { Message } from "element-ui";

const baseURL = process.env.VUE_APP_BASE_URL
const timeout = 10000

const http = axios.create({
    baseURL,
    timeout
})


http.interceptors.request.use(config => {

    if (config.url !== '/minio/upload') {
        store.commit('loading/showLoading')
    }
    if (store.state.login.token) {
        config.headers['token'] = store.state.login.token
    }
    return config
}, err => { 
    Message.error('网络错误')
    return Promise.reject(err)
})

http.interceptors.response.use(res => {
    store.commit('loading/closeLoading')
    if (res.data.code === '200') {
        return res.data
    }
    return res
}, err => { 
    store.commit('loading/closeLoading')
    Message.error('网络错误')
    return Promise.reject(err)
})

export default http